package com.technique.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.technique.api.recommend.controller.RecommandController;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller
@RequestMapping("/api")
public class ApiController {
	
	
	public ApiController(){
		System.out.println("hhahahahahahahahah");
	}
	@Autowired
	private RecommandController recommandController;
	
	/*
	 * 可供考虑的方案
	 */
	@ResponseBody
	@RequestMapping("/plan/recommend/list")
	public String planRecommendList(String placeId){
		
		JSONObject json = new JSONObject();
		JSONArray array = new JSONArray();
		
		array.add(recommandController.getPlanFake());
		array.add(recommandController.getPlanFake());
		array.add(recommandController.getPlanFake());
		array.add(recommandController.getPlanFake());
		array.add(recommandController.getPlanFake());
		array.add(recommandController.getPlanFake());
		array.add(recommandController.getPlanFake());
		array.add(recommandController.getPlanFake());
		json.put("min_id", 1);
		json.put("max_id", 1000);
		json.put("count", 10);

		json.put("plans", array);
		return json.toString();
		
	}

	/*
	 * 可供考虑的方案
	 */
	@ResponseBody
	@RequestMapping("/shop/recommend/list")
	public String shopRecommendList(String placeId){
		
		JSONObject json = new JSONObject();
		JSONArray array = new JSONArray();
		
		array.add(recommandController.getFakeShop());
		array.add(recommandController.getFakeShop());
		array.add(recommandController.getFakeShop());
		array.add(recommandController.getFakeShop());
		array.add(recommandController.getFakeShop());
		array.add(recommandController.getFakeShop());
		array.add(recommandController.getFakeShop());
		array.add(recommandController.getFakeShop());
		json.put("min_id", 1);
		json.put("max_id", 1000);
		json.put("count", 10);
		json.put("shops", array);
		return json.toString();
		
	}
	
	
	
	
	
	/*
	 * 可供考虑的方案
	 */
	@ResponseBody
	@RequestMapping("/plan/list")
	public String listPlan(String placeId){
		return this.planRecommendList(placeId);
	}
	

	@ResponseBody
	@RequestMapping(method=RequestMethod.GET,value="/plan/show")
	public String showPlan(Long planId){
		return this.recommandController.getRecommendPlan();
	}

	
	@ResponseBody
	@RequestMapping("/order/list")
	public String listOrder(Integer state){
		JSONObject json = new JSONObject();
		JSONArray array = new JSONArray();
		for(int i=0;i<10;i++){
			JSONObject order =new JSONObject();
			order.put("id", 1111);
			order.put("locations", "瑞士、法国");
			order.put("people_count", "4人");
			order.put("total_price", "¥40,000.00");
			order.put("需付", "¥30,000.00");
			order.put("退款", "¥30,000.00");
			order.put("image", "");
			array.add(order);
		}
		
		json.put("orders", array);
		return json.toString();
	}
	
	
	/**
	 * 确认订单，并支付订金
	 * @param orderId
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/order/deal.json")
	public String deal(){
		return  "{\"result\":true}";
	}
	
	/**
	 * 确认订单，并支付订金
	 * @param orderId
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/order/finish")
	public String finishOrder(){
		return  "{\"result\":true}";
	}
	
	
	
	@ResponseBody
	@RequestMapping("/order/show")
	public String showOrder(Long orderId){
		JSONObject json = new JSONObject();
		JSONArray array = new JSONArray();
		json.put("activities", array);
		return json.toString();
	}
	

	/**
	 * 取消订单
	 * @param state
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/order/cancel")
	public String cancelOrder(Long orderId,String reason){
		return  "{\"result\":true}";
	}
	
	

	/**
	 * 取消订单
	 * @param state
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/user/show")
	public String showUser(Long id){
		JSONObject json = new JSONObject();
		
		json.put("id", 1001);
		json.put("name", "米洛洛");
		json.put("gender", "m");
		json.put("age", 20);
		json.put("email", "incent@qq.com");
		
		JSONObject image = new JSONObject();
		image.put("large", "");
		image.put("middle","");
		image.put("small", "");
		json.put("image", image);
		json.put("passport_no", "11231232312");
		json.put("passport_exp_date", "2018/09/01");
		

		json.put("phone", "152xxxxxxxx123");
		
		return json.toString();
	}
	
	/**
	 * 取消订单
	 * @param state
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/location/list")
	public String listLocation(String type){
		JSONObject json = new JSONObject();
		JSONArray array = new JSONArray();
		
		for(int i =0;i<10;i++){
			JSONObject location = new JSONObject();
			location.put("id", 100);
			location.put("name", "巴黎");
			array.add(location);
		}
		
		json.put("locations", array);
		
		return json.toString();
	}

}
